package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * TODO
 *
 * @Author lyh
 * @Date 2024/11/13 10:14
 */
@Configuration
public class RabbitConfig {
    @Bean
    public Queue simpleQueue(){
        return new Queue("simple.queue");
    }
    @Bean
    public Queue workQueue(){
        return new Queue("work.queue");
    }
    /**
     * 声明广播队列1
     * @return
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 声明广播队列2
     * @return
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 声明交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * 声明广播交换机和队列的绑定关系
     * @param fanoutQueue1
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding binding(Queue fanoutQueue1,FanoutExchange fanoutExchange){
      return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }
    /**
     * 声明广播交换机和队列的绑定关系
     * @param fanoutQueue2
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding binding2(Queue fanoutQueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }
}
